home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
Libraries
/
VideoToolbox 96.06.15
/
VideoToolboxSources
/
ShowAndSaveGWorld.c
< prev
next >
Wrap
Text File
|
1995-07-20
|
3KB
|
100 lines
/*
ShowAndSaveGWorld.c
This shows a GWorld image on the selected device and saves it to disk as a PICT or eps file.
I find it useful when preparing images for demos, etc.
The image is displayed on-screen in the supplied size. However, before saving to
disk it is expanded by the "expand" factor.
Here are the bare bones of a program to use ShowAndSaveGWorld:
int screen=1,savePICT=0,saveEPS=1;
GDHandle device;
double expand=2;
screen=ChooseScreen(screen,"Which screen?");
device=GetScreenDevice(screen);
savePict=Choose(savePict,"Save image to disk as a PICT file?\n",noYes,2);
saveEPS=Choose(saveEPS,"Save image to disk as an EPS file?\n",noYes,2);
// add code here to create your GWorld and put an interesting image in it.
ShowAndSaveGWorld(world,device,expand,"interesting",savePict,saveEPS);
DisposeGWorld(world);
HISTORY:
3/20/95 dgp wrote it to produce illustrations for Discover Magazine.
6/30/95 dgp added to the VideoToolbox, while I was preparing demos for my NIH application.
*/
#include "VideoToolbox.h"
void ShowAndSaveGWorld(GWorldPtr smallWorld,GDHandle device,double expand
,char *filename,Boolean savePict,Boolean saveEPS);
void ShowAndSaveGWorld(GWorldPtr smallWorld,GDHandle device,double expand
,char *filename,Boolean savePict,Boolean saveEPS)
{
char string[100];
Rect pageRect,paperRect,r;
long copyMode;
WindowPtr window,oldPort;
ColorTable **ct;
int error;
// show it
assert(device!=NULL);
assert(smallWorld!=NULL);
assert(IsGWorldPtr(smallWorld));
ct=(**GetGWorldPixMap(smallWorld)).pmTable;
assert(ct!=NULL);
error=GDSetEntriesByType(device,0,(**ct).ctSize,(**ct).ctTable);
window=GDOpenWindow1(device);
assert(window!=NULL);
r=smallWorld->portRect;
OffsetRect(&r,-r.left,-r.top);
SectRect(&r,&window->portRect,&r);
SizeWindow(window,r.right,r.bottom,0);
GetPort(&oldPort);
SetPort(window);
EraseRect(&window->portRect);
SetPort(oldPort);
if(GDPixelSize(device)==GDPixelSize(GetGWorldDevice(smallWorld)))copyMode=srcCopyLiterally;
else copyMode=srcCopy;
r=smallWorld->portRect;
CenterRectInRect(&r,&window->portRect);
error=CopyWindows(smallWorld,(CWindowPtr)window
,&smallWorld->portRect,&r,copyMode,NULL);
if(error)PrintfExit("%s line %d: CopyWindows error %d\n",__FILE__,__LINE__,error);
if(0){
// show it, bigger
r=smallWorld->portRect;
ExpandRect(&r,expand,expand);
printf("Hit return to continue.\n");
gets(string);
SizeWindow(window,r.right,r.bottom,1);
CenterRectInRect(&r,&window->portRect);
error=CopyWindows(smallWorld,(CWindowPtr)window,&smallWorld->portRect,&r,copyMode,NULL);
if(error)PrintfExit("%s line %d: CopyWindows error %d\n",__FILE__,__LINE__,error);
}
if(savePict){
sprintf(string,"%s.pict",filename);
PixMapToPICT(string,smallWorld->portPixMap
,&smallWorld->portRect,2,NULL);
printf("Image was saved to disk as file “%s”.\n",string);
}
if(saveEPS){
pageRect=smallWorld->portRect;
ExpandRect(&pageRect,expand,expand);
pageRect.top*=-1; // convert from Apple to Adobe coordinates
pageRect.bottom*=-1; // convert from Apple to Adobe coordinates
SetRect(&paperRect,0,11*72,8.5*72,0);
CenterRectInRect(&pageRect,&paperRect);
sprintf(string,"%s.eps",filename);
WindowToEPS(smallWorld,string,&smallWorld->portRect,&pageRect,0,0,NULL);
printf("Image was saved to disk as file “%s”.\n",string);
}
printf("Hit return to continue.\n");
gets(string);
GDDisposeWindow1(window);
RestoreDeviceClut(device);
}